package com.didispace.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class TestController {

    @Value("${from}")
    private String from;

    @RequestMapping("/from")
    public String from() {
        return this.from;
    }

    // 除了通过 @Value 注解绑定注入之外，也可以通过 Environment 对象来获取配置属性  p273
    // @Autowired
    // private Environment env;
    //
    // @RequestMapping("/from")
    // public String from() {
    //     return env.getProperty("from", "undefined");
    // }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getFrom() {
        return from;
    }

    @Value("${name}")
    private String name;

    @RequestMapping("/name")
    public String name() {
        return this.name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

// spring.cloud.config.profile=test
// spring.cloud.config.label=prod
// spring.cloud.config.uri=http://localhost:7001/
// http://localhost:7002/from  等价于  http://localhost:7001/prod/didispace-test.properties
// git-test-1.0-prod-config-repo

//  /{application}-{profile}.properties
//  /{label}/{application}-{profile}.properties  p270


// spring.cloud.config.profile=prod
// spring.cloud.config.label=dev
// spring.cloud.config.uri=http://localhost:7001/
// http://localhost:7002/from

// 全局参数  属性覆盖  p280
// spring.cloud.config.server.overrides.name=didi
// http://localhost:7002/name
// didi